"""Playwright 支持调用系统已安装的浏览器，无需额外下载 Chromium
本地已安装 Google Chrome 和 Microsoft Edge，可以跳过 Playwright 自带的 Chromium 安装，直接复用现有浏览器，避免下载问题
Chrome 默认路径：
C:\Program Files\Google\Chrome\Application\chrome.exe
或 C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

Edge 默认路径：
C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
"""
from playwright.sync_api import sync_playwright

exec_path = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"
exec_path = "C:\\Users\\27727\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
with sync_playwright() as p:
    # 使用本地 Chrome
    browser = p.chromium.launch(
        executable_path=exec_path,
        headless=False  # 显示浏览器界面
    )
    page = browser.new_page()
    page.goto("https://www.baidu.com")
    print(page.title())
    browser.close()